<?php /*
	
*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}
if(isset($_REQUEST['submit']) && trim($_REQUEST['submit'])=="Change")
{
	$adminid=$_REQUEST["intcusid"];
	$newpass=md5($_REQUEST['new_pass']);
	$pass=$_REQUEST['new_pass'];
	$Loginqry = "SELECT * from `tblcustomers` WHERE `intcusid` = '$adminid'";
	$res=$obj_db->select($Loginqry);
	$email=$res[0]['varcustemail'];
///	echo md5($_REQUEST['old_pass']);die();
	$to=$email;
	//echo $Loginqry;
	//die();
	$resqry = mysql_query($Loginqry) or die("ERROR:".mysql_error());
	$numrows = mysql_num_rows($resqry);
	if($numrows > 0)
	{
	    $fetchqry=mysql_fetch_array($resqry);
	    $password=$fetchqry['varcustpassword'];
		//echo $password."/".md5($_REQUEST['old_pass']);die();
		if($password==md5($_REQUEST['old_pass']))
		{
			$sql_upd=" UPDATE `tblcustomers` SET 
			`varcustpassword` = '$newpass'
			WHERE `intcusid`='$adminid'";
			mysql_query($sql_upd);
			header("Location:customer.php");
			
		$sqlsett = "select * from tblmystore";
		$resset = $obj_db->select($sqlsett);
		if($resset){$frm=$resset[0]['varfromemail']; $store=$resset[0]['varstorename'];}
		$from=$frm;
		
		$headers="From:".$frm;
		$message="Your current Password at on ".SITENAME." has been changed by an admin for Security purpose , your new account details are as below \n Userid:".$email."\n Password:".$pass."\n\nFor more information contact us at ".$email;
		
		//$message="Your new Password is: ".$newpass;
		$mailsubject=SITENAME." account details have been updated by an administrator";
		mail($to, $mailsubject, $message, $headers);
		}
		else
		{
			header("Location:changecustomerpassword.php?msg1=invalid");
		}
		
		
	}
	else
	    header("Location:changecustomerpassword.php?msg=chp");
	
}
?>
<script type="text/javascript">

function validation()
{
	if(document.change.new_pass.value=="")
	{
		alert("Please Enter New Password..!")
		document.change.new_pass.focus();
		return false;
	}
	if(document.change.new_pass.value!=document.change.con_pass.value)
	{
		alert("Confirm Password does Not Match to the New Password..!")
		document.change.con_pass.focus();
		return false;
	}
}
</script>
<?php include("inc/header.php");?>
<body>
<table width="80%" border="0" cellspacing="0" cellpadding="0" align="center" class="middlebackground">
  <tr>
    <td align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0" >
  <tr>
    <td align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><?php include(INC."top.inc.php");?></td>
      </tr>
      <tr>
        <td height="500" valign="top" ><table width="100%" border="0" cellspacing="0" cellpadding="0">
          
          
          <tr>
            <td height="300" align="left" class="style12" style="padding:15px;"><table width="353" border="0" align="center" cellpadding="5" cellspacing="5" class="border" bgcolor="#FFFFFF">
          <tr>
            <td width="331" height="30" align="center" bgcolor="#000000" class="fntstyle"> Change Password</td>
          </tr>
          <tr>
           
			<td style="padding-left:10px; padding-right:10px;"><form method="post" name="change" id="change">
                <table  border="0" cellspacing="5" cellpadding="0">
				<?php if(isset($_REQUEST['msg1']) && trim($_REQUEST['msg1'])=="invalid"){?>
                  <tr>
                    <td height="40" colspan="2" align="center" class="style23 text style1" >Old password does not match the one stored in the database</td>
                    </tr>
					<?php }?>
                    <tr>
                      <td class="font" >Old Password : </td>
                      <td><input name="old_pass" type="password" id="old_pass" size="25" /></td>
                    </tr>
                    <tr>
                      <td class="font" >New Password : </td>
                      <td><input name="new_pass" type="password" id="new_pass" size="25" /></td>
                    </tr>
                    <tr>
                    <td class="font" >Confirm Password  : </td>
                    <td><input name="con_pass" type="password" id="con_pass" size="25" />                    </td>
                  </tr>
                  
                  <tr>
                    <td colspan="2" class="style15">&nbsp;</td>
                    </tr>
                  <tr>
                    <td colspan="2" align="center"><input name="submit" type="submit" class="btnbg" value="Change" onClick="return validation();" border="0" />                    </td>
                    </tr>
                </table>
            </form></td>
          </tr>
        </table> </td>
          </tr>
        </table></td>
      </tr>
      
    </table></td>
  </tr>
</table></td>
  </tr>
</table>

</body>
</html>
